
let spotAccounApp = null

import { createApp } from "vue";
import TradingTable from "@/content-scripts/components/table/TradingTable.vue";
import Antd from "ant-design-vue";
import { get } from "@/http/http";

import { spotsAccountCol } from '@/content-scripts/components/table/columns/spotFundsColumns'

export async function createInStockAccout(params = {}) {
    console.log(params, "createInStockAccoutcreateInStockAccout params");
    const container =
        document.querySelector(".dataTables_wrapper > .my_funds_table")
    // const table = container.querySelector('.tr-trade__table')
    // table.style.display = 'none'
    // 请求接口，获取数据
    // params是修改的数据
    const res = await get('/spot/funds/table/list', params);
    const tableSource = res.data
    const tableColumns = spotsAccountCol
    if (!container) {
        console.log(
            ".dataTables_wrapper > .my_funds_table"
        );
    }
    container.querySelector('thead').setAttribute('style', 'visibility: hidden;')
    container.querySelector('tbody').setAttribute('style', 'visibility: hidden;')
    const existingOverlay = container.querySelector(".my-spot-account-table-overlay");
    if (existingOverlay) {
        existingOverlay.remove();
    }

    const overlay = document.createElement("div");
    overlay.setAttribute("class", "my-spot-account-table-overlay");
    overlay.setAttribute(
        "style",
        "position: absolute;\n" +
        " left: 0;\n" +
        " top: 0;\n" +
        " width: 100%;\n" +
        " height: 200px;\n"
    );

    const tableStyle = {
        // fontSize: "12px",
        color: "#8e949e",
        background: "#F8F9FB",
    };

    // 挂载元素
    const appContainer = document.createElement("div");

    spotAccounApp = createApp(TradingTable);
    spotAccounApp.provide("tableSource", tableSource);
    spotAccounApp.provide("tableColumns", tableColumns);
    spotAccounApp.provide("tableStyle", tableStyle);
    spotAccounApp.use(Antd);
    spotAccounApp.mount(appContainer);
    console.log("TradingTable");

    container.style.position = "relative";
    overlay.appendChild(appContainer);
    container.appendChild(overlay);
}